<?php

class HTML_FormElements_Input extends FormElements implements HTMLElements {
	private $attributeAccept;
	private $attributeChecked;
	private $attributeReadonly;
	
	const HTML_INPUT = 'input';
	const TYPE_CHECKBOX = 'checkbox';
	const TYPE_FILE = 'file';
	const TYPE_HIDDEN = 'hidden';
	const TYPE_PASSWORD = 'password';
	const TYPE_RADIO = 'radio';
	const TYPE_TEXT = 'text';
	
	const ATTRIBUTE_ACCEPT = 'accept';
	const ATTRIBUTE_CHECKED = 'checked';
	const ATTRIBUTE_READONLY = 'readonly';
	
	/**
	 * 
	 * This function creates a complete Link-Element.
	 * The attributes have to be passed within an array. Possible attributes are:
	 * 	- $class
	 * 	- $id
	 * 	- $title
	 *  - $name
	 *  - $type
	 *  - $value
	 *  - $accept
	 *  - $checked
	 *  - $readonly
	 * @param Object $parent
	 * @param String[][] $properties
	 */
	public function __construct($parent, $properties)  {
		PropertySetter::setProperties($this, $properties);
		$parent->addChildElement($this);
	}
	
	public function setAttributeAccept ($accept)  {
		$this->attributeAccept = $accept;
	}
	
	public function setAttributeChecked ($checked)  {
		$this->attributeChecked = $checked;
	}
	
	public function setAttributeReadonly ($readonly)   {
		$this->attributeReadonly = $readonly;
	}
	
	public function getAttributeAccept ()  {
		return $this->attributeAccept;
	}
	
	public function getAttributeChecked ()  {
		return $this->attributeChecked;
	}
	
	public function getAttributeReadonly ()  {
		return $this->attributeReadonly;
	}
	
	public function getInputAttributes ()  {
		
		$output = '';
		
		if (!empty($this->attributeReadonly))  {
			$output .= ' '. self::ATTRIBUTE_READONLY. '="'. $this->getAttributeReadonly(). '"';
		}
		if (!empty($this->attributeChecked))  {
			$output .= ' '. self::ATTRIBUTE_CHECKED. '="'. $this->getAttributeChecked(). '"';
		}
		if (!empty($this->attributeAccept))  {
			$output .= ' '. self::ATTRIBUTE_ACCEPT. '="'. $this->getAttributeAccept(). '"';
		}
	}
	
	public static function getAttributes ()  {
		$attributes = array();
		$parentAttributes = parent::getAttributes();
		$attributes[] = self::ATTRIBUTE_ACCEPT;
		$attributes[] = self::ATTRIBUTE_CHECKED;
		$attributes[] = self::ATTRIBUTE_READONLY;
		return array_merge($parentAttributes, $attributes);
	}
	
	public function toString ()  {
		$output = '<'. self::HTML_INPUT.
					$this->getHTMLAttributes().
					$this->getFormElementsAttributes().
					$this->getInputAttributes(). '/>';
		
		return $output;
	}
	
}

?>